/**
 * @param {number[][]} grid
 * @return {number}
 */
var numberOfRightTriangles = function(grid) {
  let result = 0
  let row = []
  let col = []
  for(let i = 0; i < grid[0].length; i++) {
    let demoCol = 0
    for(let j = 0; j < grid.length; j++) {
      demoCol += grid[j][i]
      if (row.length < grid.length) {
        row.push(grid[j].reduce((pre, cur) => pre + cur)) 
      }
    }
    col.push(demoCol)
  }

  console.log("%c Line:20 🍔", "color:#ffdd4d", col);
  console.log("%c Line:18 🍩row", "color:#b03734", row);

  for(let i = 0; i < grid.length; i++) {
    for(let j = 0; j < grid[0].length; j++) {
      let num = grid[i][j]
      if (num === 1 && row[i] >= 2 && col[j] >= 2) {
        result ++;
        if (row[i] >= 3 || col[j] >= 3) {
          result++;
        }
      }
    }
  }

  return result
};